﻿using System;
using System.Drawing;
using System.Windows.Forms;
using NIKE_Project.BLL;
using NIKE_Project.Model;

namespace NIKE_Project.UI
{
    public partial class Register : Form
    {
        public Register()
        {
            InitializeComponent();
        }
        //注册窗体加载事件 
        private void register_Load(object sender, EventArgs e)
        {
            //默认选中男
            this.radioButton1.Checked = true;
            this.label13.Visible = false;
        }
        //注册单击事件
        private void button1_Click(object sender, EventArgs e)
        {
            var model = new RegisterModel
            {
                SalesmanID = label12.Text,
                SalesmanName = this.textBox1.Text,
                Mobile = this.textBox2.Text,
                Pwd = this.textBox3.Text,
                Pwd1 = this.textBox4.Text,
                Role = this.comboBox1.Text,
                BaseSalary = this.textBox5.Text,
                CommissionRate = this.textBox6.Text,
                Gender = this.radioButton1.Checked? "男": this.radioButton2.Checked?"女":""//判断单选按钮的值
            };
            if (model.Pwd != model.Pwd1)
            {
                this.label13.Visible = true;
            }
            else
            {
                this.label13.Visible = false;
                try
                {
                    var server = new RegisterServer();
                    server.RegisterUser(model);
                    this.label13.Visible = false;
                    var Result = MessageBox.Show("店长注册成功", "提示", MessageBoxButtons.OK);
                    if (Result == DialogResult.OK)
                    {
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        //确认密码判断
        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            if (this.textBox3.Text != this.textBox4.Text)
            {
                this.label13.Visible = true;
                this.label13.Text = "两次输入的密码不一致，请确认！";
                //设置提示的字体颜色为红色
                //this.label37.ForeColor = Color.Red;
                this.label13.ForeColor = ColorTranslator.FromHtml("#ff0000");
            }
            else
            {
                this.label13.Visible = false;
            }
        }

        //取消单击事件
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_register_Click(object sender, EventArgs e)
        {
            label12.Text = "";//清空用户ID，使其变为注册
            button1_Click(sender,e);
        }
    }
}
